#include "clist.h"

int	CList::clear()
{
	cur = max = 0;
	return 0;
}

int	CList::isDone()
{
	if ( cur >= max )
		return 1;
	else
		return 0;
}

int	CList::toStart()
{
	cur = 0;
	return 0;
}

int CList::add( T_MOVE m, int v )
{
	move[max] = m;
	value[max] = v;
	max++;
	return 0;
}

T_MOVE CList::get( int id )
{
	return move[id];
}

T_MOVE CList::get( )
{
	_pick(cur);
	return move[cur++];
}

int CList::_pick( int id )
{
	int best = id;
	for( int i = id+1; i < max; i++  )
	{
		if ( value[ i ] > value[ best ] )
			best = i;
	}
	T_MOVE tm 		= move[ id ];
	move[ id ]		= move[ best ];
	move[ best ]	= tm;
	int vl 			= value[ id ];
	value[ id ]		= value[ best ];
	value[ best ]	= vl;
	return 0;
}
